package com.feige.controller;


import com.feige.result.AjaxResult;
import com.feige.service.RolePermissionService;
import com.feige.service.RoleService;
import io.swagger.annotations.*;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.Arrays;

/**
 * <p>
 * 角色权限表 前端控制器
 * </p>
 *
 * @author feige
 * @since 2020-07-20
 */
@Api(tags = "角色权限类")
@RestController
@RequestMapping("/admin/role-permission")
public class RolePermissionController {


    @Resource
    private RolePermissionService rolePermissionService;


    @PreAuthorize("@ss.hasPerm('user:role:add')")
    @ApiOperation(value = "给角色分配权限")
    @PostMapping("/Assign-permissions")
    public AjaxResult AssignPermissions(@ApiParam(name = "roleId", value = "角色ID", required = true) Long roleId,
                                        @ApiParam(name = "permissionId", value = "权限ID数组", required = true) Long[] permissionId){
        boolean assignPermissions = rolePermissionService.AssignPermissions(roleId, permissionId);
        if (assignPermissions){
            return AjaxResult.success();
        }else {
            return AjaxResult.error();
        }
    }

}

